package zozopo.warehouse;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.warehouse.operations.GoodsOS;
import zozopo.warehouse.operations.GoodsTB;
import zozopo.warehouse.operations.PurchaseOS;
import zozopo.warehouse.operations.PurchaseTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class GetReceiptInfoAction extends ActionSupport implements Action,SessionAware,ServletRequestAware,ServletResponseAware{
	//传入参数
	private int warehouseid;
	private int goodsid;
	private int number;
	private double price;

	//传出参数
	private String responseText  = "";
	private int reserve;
	private double profit;
	
	HttpServletRequest request;
	HttpServletResponse response;
	private Map<Object, Object> session;
	

	
	
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=UTF-8");
	}
	
	public String execute(){
		 
		PurchaseOS purchaseOS = new PurchaseOS();
		GoodsOS goodsOS = new GoodsOS(purchaseOS.getConn());
		
		reserve = purchaseOS.getGoodsReserve(warehouseid, goodsid);
		
		
		
		GoodsTB goods = goodsOS.getGoodsById(goodsid);
			
		if(reserve < number){
			responseText=goods.getId_goods() + "," + goods.getName_goods() + "," + "库存不足!";
		}
		
		
		profit = (price - goods.getAverage_goods()) * number;
			
			
			
		purchaseOS.releaseConnection();
		
		
		return SUCCESS;
	}


	public void setGoodsid(int goodsid) {
		this.goodsid = goodsid;
	}

	public int getWarehouseid() {
		return warehouseid;
	}

	public void setWarehouseid(int warehouseid) {
		this.warehouseid = warehouseid;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getGoodsid() {
		return goodsid;
	}

	

	public String getResponseText() {
		return responseText;
	}

	public void setResponseText(String responseText) {
		this.responseText = responseText;
	}

	public int getReserve() {
		return reserve;
	}

	public void setReserve(int reserve) {
		this.reserve = reserve;
	}

	public double getProfit() {
		return profit;
	}

	public void setProfit(double profit) {
		this.profit = profit;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

}
